package cinema.ELTEcinema;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

@SuppressWarnings("serial")
@Named
@SessionScoped
public class LoginController implements Serializable{
	
	@Inject
	private LoginBean loginBean;
	
	private String uname;
	private String password;
	
	@PostConstruct
	public void init(){
		
	}
	
	public String logIn(){
		try{
			if(loginBean.logIn(uname, password)){
				return "admin";
			}
			else{
				FacesContext.getCurrentInstance().addMessage("UserName",
		                new FacesMessage(FacesMessage.SEVERITY_ERROR, "wrong username or password", "wrong username or password"));
				return null;
			}
		}
		catch(Exception e){
			return null;
		}
		
	}
	
	public String getuname() {
		return uname;
	}
	public void setuname(String uname) {
		this.uname = uname;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}